<template>
  <div class="bg">
    <div class="login_box">
      <div class="left">
        <div class="img_box">
          <img src="../assets/img/undraw_my_password_re_ydq7 1.png" alt="">
        </div>
      </div>
      <div class="right">
        <p>重置密码</p>
        <el-form :model="resetForm"
         :rules="resetRules"
          ref="resetFormRef"
          label-position="top"
          class="reset_form"
          >
          <el-form-item label="密码" prop="newPasswd" class="item">
            <el-input :type="classes1" v-model.trim="resetForm.newPasswd" >
              <i slot="suffix" class="el-icon-view" @click="showNewPasswd"></i>
            </el-input>
          </el-form-item>
          <el-form-item label="重复密码" prop="confirmPasswd" class="item">
            <el-input :type="classes2" v-model.trim="resetForm.confirmPasswd" @change="check">
              <i slot="suffix" class="el-icon-view" @click="showCnfirmPasswd"></i>
            </el-input>
          </el-form-item>
          <el-form-item>
            <div class="tip">
              <span class="level">密码强度:</span>
              <span :class="pwdLevel">{{LevelCon}}</span>
            </div>
          </el-form-item>
          <el-form-item class="btns">
            <el-button type="primary" @click="reset">重置密码</el-button>
          </el-form-item>
        </el-form>
        <div class="bottom-left">
          <span>你已有账号?</span>
          <el-button type="text" @click="login"><span>用户登录</span></el-button>
        </div>
        <div class="bottom-right">
          <span>建立新账号?</span>
          <el-button type="text" @click="reguser"><span>用户注册</span></el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      resetForm: {
        newPasswd: '',
        confirmPasswd: ''
      },
      classes1: 'password',
      classes2: 'password',
      checked: false,
      resetRules: {
        newPasswd: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 8, max: 20, message: '长度在 8 到 20 个字符', trigger: 'blur' }
        ],
        confirmPasswd: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 8, max: 20, message: '长度在 8 到 20 个字符', trigger: 'blur' }
        ]
      },
      pwdLevel: '',
      LevelCon: ''
    }
  },
  methods: {
    // 密码明文密文转换
    showNewPasswd () {
      // 点击图标是密码隐藏或显示
      if (this.classes1 === 'text') {
        this.classes1 = 'password'
        // 更换图标
      } else {
        this.classes1 = 'text'
      }
    },
    // 密码明文密文转换
    showCnfirmPasswd () {
      // 点击图标是密码隐藏或显示
      if (this.classes2 === 'text') {
        this.classes2 = 'password'
        // 更换图标
      } else {
        this.classes2 = 'text'
      }
    },
    check () {
      // 弱密码：全是数字或全是字母，8-20个字符
      const weakReg = /^[0-9]{8,20}$|^[a-zA-Z]{8,20}$/

      // 中密码：至少一个字母和一个数字
      const mediumReg = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,20}$/

      // 强密码：至少一个字母，一个数字和一个特殊字符
      const strongReg = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,20}$/
      // console.log('this.resetForm.confirmPasswd.match(strongReg) ', this.resetForm.confirmPasswd.match(strongReg))
      if (this.resetForm.confirmPasswd.length >= 8 && this.resetForm.confirmPasswd.length <= 20) {
        if (this.resetForm.confirmPasswd.match(weakReg)) {
          // console.log(' this.resetForm.confirmPasswd.match(weakReg)', this.resetForm.confirmPasswd.match(weakReg))
          this.pwdLevel = 'one'
          this.LevelCon = '简单'
        } else if (this.resetForm.confirmPasswd.match(mediumReg)) {
          this.pwdLevel = 'two'
          this.LevelCon = '复杂'
        } else if (this.resetForm.confirmPasswd.match(strongReg)) {
          this.pwdLevel = 'three'
          this.LevelCon = '很强'
        }
      }
    },
    login () {
      this.$router.push({ path: '/login' })
    },
    reguser () {
      this.$router.push({ path: '/reguser' })
    },
    forget () {
      this.$router.push({ path: '/forget' })
    },
    reset () {
      this.$refs.resetFormRef.validate(valid => {
        // eslint-disable-next-line no-useless-return
        if (!valid) return
        if (this.resetForm.newPasswd === this.resetForm.confirmPasswd) {
          this.$message.success('重置成功，3秒后跳转至登录页！')
          this.$refs.resetFormRef.resetFields()
          setTimeout(() => {
            this.$router.push({ path: '/login' })
          }, 3000)
        } else {
          this.$message.error('密码不一致，请检查！')
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
  .bg {
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f7f7f7;
    overflow-y: hidden;
  }

  .login_box {
    width: 1440px;
    height: 1024px;
    background-color: #fff;
    display: flex;
  }
  .left {
    width: 720px;
    height: 1024px;
    background-color: #9A9AEB;
    position: relative;
    .img_box {
      width: 493.46px;
      height: 480.85px;
      position: absolute;
      top: 301px;
      left: 139px;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  .right {
    width: 720px;
    height: 1024px;
    position: relative;
    p {
      position: absolute;
      width: 385px;
      height: 38px;
      top: 224px;
      right: 148px;
      margin-bottom: 0px;
      color: rgb(0, 0, 0);
      font-family: Roboto;
      font-size: 32px;
      font-weight: 500;
      line-height: 38px;
      letter-spacing: 0%;
      text-align: left;
    }
  }
  .reset_form {
    position: absolute;
    top: 301px;
    left: 127px;
    width: 446px;
    margin-top: 39px;
    .item ::v-deep .el-form-item__label {
      padding-top: 15px;
      color: rgb(0, 0, 0);
      font-family: Roboto;
      font-size: 24px;
      font-weight: 400;
      line-height: 28px;
      letter-spacing: 0%;
      text-align: left;
    }
    .el-input ::v-deep .el-form-item {
      margin-bottom: 0px;
    }
    // .el-form-item {
    //   margin-bottom: 30px;
    // }
    .el-input ::v-deep .el-input__inner {
      border:1px solid #4D4DDB;
    }
  }
  .checkbox ::v-deep .el-checkbox__label {
    padding-top: 10px;
    color: rgb(0, 0, 0);
    font-family: Roboto;
    font-size: 20px;
    font-weight: 400;
    line-height: 23px;
    letter-spacing: 0%;
    text-align: left;
  }
  .forget {
    float: right;
      .el-button{
        padding: 0px;
        width: 80px;
        height: 23px;
        color: rgb(0, 0, 0);
        font-family: Roboto;
        font-size: 20px;
        font-weight: 400;
        line-height: 23px;
        letter-spacing: 0%;
        text-align: left;
      }
  }
  .btns {
    display: flex;
    justify-content: center;
    .btns ::v-deep .el-button--primary {
      width: 446px;
      height: 55px;
    }
    .el-button {
      margin: 0px;
      width: 446px;
      height: 55px;
      background: rgb(30, 30, 30);
      border-radius: 8px;
      color: rgb(255, 255, 255);
      font-family: Roboto;
      font-size: 24px;
      font-weight: 500;
      line-height: 28px;
      letter-spacing: 0%;
      text-align: center;
    }
    .btns ::v-deep .el-button:focus, .el-button:active {
      background: #66b1ff;
      border-color: #66b1ff;
      color: #FFF;
    }
  }
  .bottom-left {
    position: absolute;
    width: 205px;
    height: 23px;
    top: 700px;
    left: 127px;
    text-align: center;
    span {
      font-family: Roboto;
      font-size: 20px;
      font-weight: 400;
      line-height: 23px;
      letter-spacing: 0%;
    }
    .el-button {
      padding: 0;
    }
  }
  .bottom-right {
    position: absolute;
    width: 205px;
    height: 23px;
    top: 700px;
    right: 148px;
    text-align: center;
    span {
      font-family: Roboto;
      font-size: 20px;
      font-weight: 400;
      line-height: 23px;
      letter-spacing: 0%;
    }
    .el-button {
      padding: 0;
    }
  }
  .tip{
    width: 125px;
    height: 23px;

    .level{
      color: rgb(0, 0, 0);
      font-family: Roboto;
      font-size: 20px;
      font-weight: 400;
      line-height: 23px;
      letter-spacing: 0%;
      text-align: left;
    }
    .one {
      color: red;
      font-family: Roboto;
      font-size: 20px;
      font-weight: 400;
      line-height: 23px;
      letter-spacing: 0%;
      text-align: left;
    }
    .two {
      color: #66c2ff;
      font-family: Roboto;
      font-size: 20px;
      font-weight: 400;
      line-height: 23px;
      letter-spacing: 0%;
      text-align: left;
    }
    .three {
      color: #00ff85;
      font-family: Roboto;
      font-size: 20px;
      font-weight: 400;
      line-height: 23px;
      letter-spacing: 0%;
      text-align: left;
    }
  }

</style>
